package net.qiqb.core.domain;

import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.implementation.bind.annotation.Super;
import net.qiqb.core.domain.annotation.EntityIdGenerator;
import net.qiqb.core.executing.ExecutingContextHolder;

/**
 * 聚合根拦截
 */
@Slf4j
public class EntityIdGeneratorAdvisor {


    public static Object generate(@Super EntityIdGenerator<Object> entityIdGenerator) throws Exception {
        final Object entityId = entityIdGenerator.generate();
        ExecutingContextHolder.current().addNewEntityId(entityId);
        return entityId;
    }
}
